import nyNetwork from "@/api/nyBaseNetwork";
import DZModelPage from "@/model/DZModelPage";
import nyMessageToast from "@/utils/NYMessageToast";
import DZModelOrder from "../model/DZModelOrder";
import DZModelUserAssess from "../model/DZModelUserAssess";
import DZModelUserExpert from "../model/DZModelUserExpert";

class DZServiceOrder {


    m_page = new DZModelPage(10);

    list_order: Array<DZModelOrder> = [];

    m_screen = {
        goodsType: null,
        status: null,
        time: ''
    }

    m_user_assess_info = new DZModelUserAssess();

    m_user_expert_info = new DZModelUserExpert();


    net_list_order() {
        var arr_data = [];
        nyNetwork.net("订单列表", { ...this.m_screen, ...this.m_page }, data => {
            this.m_page.total = data.total;
            for (const item of data.list) {
                var model = new DZModelOrder();
                model.orderNum = item.sorderNum ?? '';
                model.wxOrderNum = item.wxOrderNum ?? '';
                model.goodsName = item.sname ?? '';
                model.goodsPrice = item.itruePrice ? '￥' + item.itruePrice / 100 : '';
                model.createTime = item.createTime ?? '';
                model.payPrice = item.ipayPirce ? '￥' + item.ipayPirce / 100 : '';
                model.payTime = item.payTime ?? '';
                model.payTime = model.payTime.replace("T", ' ')
                model.payTime = model.payTime.replace("+08:00", '')
                model.payType = item.payType == 2 ? '优惠券' : '微信'
                model.coupon = item.coupon ?? '';
                model.status = item.istatus ?? -1;
                model.type = item.itype ?? 0;
                arr_data.push(model);
            }
            this.list_order = arr_data;
        })
    }

    net_assess_info(success: () => void) {
        nyNetwork.net("测评用户信息", { orderNum: this.m_user_assess_info.orderNum }, data => {
            if (data) {
                this.m_user_assess_info.parse(data);
                success();
            } else {
                nyMessageToast.error("用户未完善信息")
            }

        })
    }

    net_expert_info(success: () => void) {
        nyNetwork.net("预约咨询详情", { orderNum: this.m_user_expert_info.orderNum }, data => {
            if (data) {
                this.m_user_expert_info.parse(data);
                success();
            } else {
                nyMessageToast.error("用户未完善信息")
            }
        })
    }

    net_down_load(path) {
        nyNetwork.download("下载文件", "?path=" + encodeURIComponent(path));
    }
}
export default DZServiceOrder;